package cn.kmsoft.common.utils;

/**
 * @author : cqwensten
 * @description : todo
 * @email : cqwensten@163.com
 * @date : 2021/11/18
 */
public class DataValidUtil {
    /**
     * 判断是否有回车和换行字符
     *
     * @param inputLine
     * @return
     */
    public static boolean hasCRLF(String inputLine) {
        return inputLine.contains("\n") || inputLine.contains("\r");
    }

    /**
     * 移除回车与换行字符
     *
     * @param inputLine
     * @return
     */
    public static String removeCRLF(String inputLine) {
        String filteredLine = inputLine;

        if (hasCRLF(inputLine)) {
            filteredLine = filteredLine.replace("\n", "").replace("\r", "");
        }
        return filteredLine;
    }

    /**
     * 替换回车与换行字符
     *
     * @param inputLine
     * @param replaceString
     * @return
     */
    public static String replaceCRLF(String inputLine, String replaceString) {
        String filteredLine = inputLine;

        if (hasCRLF(inputLine)) {
            filteredLine = filteredLine.replace("\n", replaceString).replace("\r", replaceString);
        }
        return filteredLine;
    }
}
